package cn.open.feishu.alert.common.utils;

import lombok.extern.slf4j.Slf4j;

import java.io.UnsupportedEncodingException;
import java.math.BigInteger;
import java.security.MessageDigest;
import java.security.NoSuchAlgorithmException;

/**
 * @Description md5加密工具类
 * @Author fandy.lin
 * @Date 2021/11/11 4:20 下午
 **/
@Slf4j
public class Md5Util {
    public static String getEncode(String text) {
        byte[] digest = null;
        try {
            MessageDigest md5 = MessageDigest.getInstance("md5");
            digest  = md5.digest(text.getBytes("utf-8"));
        } catch (Exception e) {
            log.warn("MD5Util getEncode error,text={}",text,e);
        }
        //16是表示转换为16进制数
        String md5Str = new BigInteger(1, digest).toString(16);
        return md5Str;
    }
}
